Crispo - Excel Challenge 25 2024

excel-challenges
weekly-exercises
Easy Sunday Excel Challenge
Published

June 23, 2024

Illustration for Crispo - Excel Challenge 25 2024

Challenge Description

Easy Sunday Excel Challenge

⭐ Date & Orders Dates Easy Sunday Excel Challenge ⭐Get Dates with orders Less than the previous Date marks for Legacy solutions or PowerQuery Solution

Solutions

library(tidyverse)
library(readxl)

path = "files/Excel Challenge  22nd June.xlsx"

input = read_xlsx(path, range = "B2:B22", col_types = "text")
test  = read_xlsx(path, range = "D2:D5")

result <- tibble(
  Dates = as.POSIXct(as.Date(as.numeric(input$`Date & Orders`[seq(1, nrow(input), 2)]), 
                             origin = "1899-12-30")),
  Values = as.numeric(input$`Date & Orders`[seq(2, nrow(input), 2)])
) %>%
  filter(Values < lag(Values)) %>%
  select(Dates)

identical(result, test)
# [1] TRUE
  • Logic:

    • Applies the workbook rule directly and shapes the expected output
  • Strengths:

    • The R solution stays compact and mirrors the workbook logic closely.
  • Areas for Improvement:

    • The code assumes the workbook layout and named ranges remain stable.
  • Gem:

    • The best part of the solution is choosing a tidy intermediate shape before producing the final answer.
import pandas as pd

path = 'files/Excel Challenge  22nd June.xlsx'
input = pd.read_excel(path, skiprows = 1, usecols= "B")
test  = pd.read_excel(path, skiprows = 1, usecols= "D", nrows = 3)

input = pd.concat([input.iloc[::2].reset_index(drop=True), input.iloc[1::2].reset_index(drop=True)], axis=1)
input.columns = ['Dates', 'Values']
filtered_data = input[input['Values'] < input['Values'].shift()]
result = filtered_data[['Dates']].astype("datetime64[ns]").reset_index(drop=True)

print(result.equals(test)) # True
  • Logic:

    • Reads the workbook range needed for the challenge
  • Strengths:

    • The Python version keeps the same rule in a direct pandas-oriented workflow.
  • Areas for Improvement:

    • As with the R version, any workbook layout change would require small adjustments.
  • Gem:

    • The implementation stays close to the stated challenge instead of adding unnecessary complexity.

Difficulty Level

This task is easy to moderate:

  • The business rule is readable, but the workbook still needs a few careful transformation steps.